import { defineStore } from "pinia";
import { getToken, setToken, removeToken } from '@/utils/auth'

const useUserStore = defineStore({
  id: "user",
  // 开启数据缓存
  persist: {
    enabled: true
  },
  state: () => ({
    token: getToken(),
    name: 'admin',
    avatar: ''
  }),
  getters: {
    doubleCount: (state) => state.counter * 2
  },
  actions: {
    updateAvatar(avatar) {
      this.avatar = avatar
    },
    updateToken(token) {
      this.token = token
    },
    increment () {
      this.counter++
    }
  }
})

export default useUserStore;